<template>
  <teleport to="#modal">
    <div class="modal d-block" tabindex="-1" v-if="props.visible">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title">{{ props.title }}</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"
              @click="onClose"></button>
          </div>
          <div class="modal-body">
            <slot></slot>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal" @click="onClose">取消</button>
            <button type="button" class="btn btn-primary" @click="onConfirm">确认</button>
          </div>
        </div>
      </div>
    </div>
  </teleport>
</template>
<script setup lang="ts">
import useDOMCreate from '../hooks/useDOMCreate';
interface Props {
  // 标题
  title: string
  // 是否显示
  visible: boolean
}
// 定义 props 和默认值
const props = withDefaults(defineProps<Props>(), {
  visible: false
})
// 自定义事件   
const emits = defineEmits(['modal-on-confirm', 'modal-on-close'])
// 触发自定义事件
const onConfirm = () => {
  emits('modal-on-confirm')
}
const onClose = () => {
  emits('modal-on-close')
}
useDOMCreate('modal')
</script>